// Package main
// @Author zhongxc
// @Date 2024/1/3 11:04:00
// @Desc
package main

import "log"

func binarySearch(arr []int, target int) int {
	left, right := 0, len(arr)-1

	for left <= right {
		mid := left + (right-left)/2

		if arr[mid] == target {
			return mid
		}

		if arr[mid] < target {
			left = mid + 1
		} else {
			right = mid - 1
		}
	}

	return -1
}

func main() {
	arr := []int{1, 2, 3, 4, 9, 6, 7}
	log.Printf("%v\n", binarySearch(arr, 6))

}
